<template>
  <div>
    <el-cascader-panel
      v-model="obj.pca"
      :options="pca"
      :props="{ label: 'name', value: 'name' }"
      @change="findData"
    ></el-cascader-panel>

    <div style="margin-top: 10px">
      <div style="width: 50%; float: left">
        <el-form ref="form" :model="obj" label-width="80px">
          <el-form-item label="确诊">
            <el-input v-model="obj.confirmed"></el-input>
          </el-form-item>
          <el-form-item label="疑似">
            <el-input v-model="obj.suspected"></el-input>
          </el-form-item>
          <el-form-item label="死亡">
            <el-input v-model="obj.dead"></el-input>
          </el-form-item>
          <el-form-item label="治愈">
            <el-input v-model="obj.cure"></el-input>
          </el-form-item>
          <el-form-item label="重症">
            <el-input v-model="obj.severe"></el-input>
          </el-form-item>
          <el-form-item label="境外输入">
            <el-input v-model="obj.outside"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button @click="save">提交</el-button>
          </el-form-item>
        </el-form>
      </div>
      <div style="width: 47%; float: right; font-weight: 800; color: red">
        <div>温馨提示</div>
        <div>先选择城市</div>
        <div>在录入数据</div>
      </div>
    </div>
  </div>
</template>
<script>
import pca from "../../assets/pca.json";
import {mapActions, mapState} from 'vuex';
import moment from 'moment';
export default {
  data() {
    return {
      pca,
      options: [],
      obj: {
        country: "中国",
      },
    };
  },
  computed: {
      ...mapState('dataUpdate',['dataList'])
  },
  methods: {
      //查询某地区当天是否录入数据
      findData(val) {
        //   console.log(val);
        // console.log(moment(new Date()).format('YYYY-MM-DD'));
          //数据上报
        let params = {
            page:1,
            pageSize:1,
            area:val[2],
            inputTime:moment(new Date()).format('YYYY-MM-DD')
        }
        this.page_query(params).then(()=>{
        if(this.dataList.total > 0){
          // 修改
          console.log(this.dataList.list[0]);
          this.obj = this.dataList.list[0];
        }
      })
      },
      ...mapActions('dataUpdate',["saveOrUpdate","page_query"]),
      save() {
          if(this.obj.pca) {
                this.obj.province = this.obj.pca[0];
                this.obj.city = this.obj.pca[1];
                this.obj.area = this.obj.pca[2];
                delete this.obj.pca;
          }
        this.saveOrUpdate(this.obj).then((res)=>{
            console.log(res);
            this.$router.push({
                path:"/datalist/table",
            })
        });
        console.log(this.obj);
    },
  },
};
</script>
